from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Firefox()
driver.get("https://www.baidu.com/")

# 找到设置 元素，点击
settings = driver.find_element(by=By.ID,value="s-usersetting-top")
settings.click()
time.sleep(3)

# 找到 搜索设置 ，点击,弹窗就出来了
serach_set = driver.find_element(by=By.CLASS_NAME,value="setpref")
serach_set.click()
time.sleep(3)

# 找到每页20 条，选中
page_20 = driver.find_element(by=By.XPATH,value='//*[@id="se-setting-3"]/span[2]/label')
page_20.click()
time.sleep(3)

# 找到保存设置，点击,会出现alertdialog（警告框）
save = driver.find_element(by=By.XPATH,value='/html/body/div[1]/div[6]/div/div/div/div[1]/form/div/ul/li[6]/div/a[2]')
save.click()
time.sleep(3)

# 警告框操作需要切换，driver.switch_to.alert

# dismiss: 关闭警告框
# driver.switch_to.alert.dismiss()
# 确认
driver.switch_to.alert.accept()
